/// @tags: Inversion
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 5e5 + 2;

int lowbit(int x) { return x & (-x); }

int n;
int a[maxn], val[maxn];
bool exi[maxn];

void add(int x) {
  for (; x <= n; x += lowbit(x)) ++val[x];
}

int query(int x) {
  int ret = 0;
  for (; x; x -= lowbit(x)) ret += val[x];
  return ret;
}

void solve() {
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    exi[i] = false, val[i] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    if (exi[a[i]]) {
      cout << "YES" << endl;
      return;
    }
    exi[a[i]] = true;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += query(n) - query(a[i]);
    add(a[i]);
  }
  cout << (ans & 1 ? "NO" : "YES") << endl;
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    solve();
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("CF1585D Yet Another Sorting Problem.in", "r", stdin);
  freopen("CF1585D Yet Another Sorting Problem.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
